package errors

import "fmt"

type Error struct {
	Code int
	Message string
}


func (e *Error) Error() string {
	return e.Message
}

var errorMap = make(map[int] struct{})

func New(code int, msg string) *Error {
	if _, ok := errorMap[code]; ok {
		panic(fmt.Sprintf("错误码:%d ,消息:%s, 已被使用,请更换错误码", code, msg))
	}
	errorMap[code] = struct{}{}
	return &Error{
		Code:    code,
		Message: msg,
	}
}
